package com.meixiang.fragment.collect;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.gson.Gson;
import com.lzy.okhttputils.model.HttpParams;
import com.meixiang.R;
import com.meixiang.entity.collect.CollectEntity;
import com.meixiang.fragment.service.BaseViewPagerFragment;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;

import org.json.JSONObject;

/**
 * 收藏
 * author:xiejingwen
 */
public class CollectFragment extends BaseViewPagerFragment {
    private CollectEntity mCollectEntity;
    @Override
    protected String[] getTitles() {
        setViewpagerSlide(false);
        return new String[]{"全部","商品","服务"};
    }

    @Override
    protected Fragment[] getFragments() {
        getData();
        return new Fragment[]{new AllCollectFragment(),new CommodityFragment(),new ServiceCollectFragment()};
    }

    @Override
    protected int ColorStyle() {
        return R.color.financial_red_color ;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }
    public void getData(){
        HttpParams params = new HttpParams();
        params.put("favType","0");
        params.put("pageSize","10");
        params.put("pageNo","1");
        HttpUtils.post(Config.COLLECT_LIST, params, new HttpCallBack(getActivity()) {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                mCollectEntity = new Gson().fromJson(result.toString(),CollectEntity.class);
               setTabText(0,"全部("+mCollectEntity.getCountTotal()+")");
               setTabText(1,"商品("+mCollectEntity.getGoodsTotalRows()+")");
               setTabText(2,"服务("+mCollectEntity.getServeTotalRows()+")");
            }

            @Override
            public void onError(String code, String message) {

            }
        });
    }
}
